/*
 *  * Copyright (C) 2021 Huawei Device Co., Ltd.
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 */

package com.fractalwrench.harmonybootstrap.sample.slice;

import static com.fractalwrench.harmonybootstrap.sample.ResourceTable.*;

import com.beardedhen.harmonybootstrap.BootstrapButton;
import com.beardedhen.harmonybootstrap.utils.ResUtil;
import com.fractalwrench.harmonybootstrap.sample.*;
import com.fractalwrench.harmonybootstrap.sample.ResourceTable;

import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.LayoutScatter;

public class MainAbilitySlice extends AbilitySlice implements Component.ClickedListener {

    private BootstrapButton btn_bootstrapbadge ;
    private BootstrapButton btn_bootstrapalert ;
    private BootstrapButton btn_bootstrapwell ;
    private BootstrapButton btn_bootstraplabel;
    private BootstrapButton btn_bootstrapedittext;
    private BootstrapButton btn_bootstrapprogressbar;
    private BootstrapButton btn_bootstrapthumbnail;
    private BootstrapButton btn_bootstrapbutton;
    private BootstrapButton btn_bootstrapcirclethumbnail;
    private BootstrapButton btn_bootstrapbuttongroup;
    private BootstrapButton btn_bootstrapdropdown;
    private BootstrapButton btn_bootstrapprogressbargroup;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        ComponentContainer rootLayout = (ComponentContainer)
                LayoutScatter.getInstance(getContext()).parse(Layout_ability_main, null, false);

        btn_bootstrapbadge = ResUtil.findViewById(rootLayout, ResourceTable.Id_btn_bootstrapbadge);
        btn_bootstrapbadge.setClickedListener(this);

        btn_bootstrapalert = ResUtil.findViewById(rootLayout, ResourceTable.Id_btn_bootstrapalert);
        btn_bootstrapalert.setClickedListener(this);

        btn_bootstrapwell = ResUtil.findViewById(rootLayout, Id_btn_bootstrapwell);
        btn_bootstrapwell.setClickedListener(this);

        btn_bootstraplabel = ResUtil.findViewById(rootLayout, Id_btn_bootstraplabel);
        btn_bootstraplabel.setClickedListener(this);

        btn_bootstrapedittext = ResUtil.findViewById(rootLayout, Id_btn_bootstrapedittext);
        btn_bootstrapedittext.setClickedListener(this);

        btn_bootstrapprogressbar = ResUtil.findViewById(rootLayout, Id_btn_bootstrapprogressbar);
        btn_bootstrapprogressbar.setClickedListener(this);

        btn_bootstrapthumbnail = ResUtil.findViewById(rootLayout, Id_btn_bootstrapthumbnail);
        btn_bootstrapthumbnail.setClickedListener(this);

        btn_bootstrapbutton = ResUtil.findViewById(rootLayout, Id_btn_bootstrapbutton);
        btn_bootstrapbutton.setClickedListener(this);

        btn_bootstrapcirclethumbnail = ResUtil.findViewById(rootLayout, Id_btn_bootstrapcirclethumbnail);
        btn_bootstrapcirclethumbnail.setClickedListener(this);

        btn_bootstrapbuttongroup = ResUtil.findViewById(rootLayout, Id_btn_bootstrapbuttongroup);
        btn_bootstrapbuttongroup.setClickedListener(this);

        btn_bootstrapdropdown = ResUtil.findViewById(rootLayout, Id_btn_bootstrapdropdown);
        btn_bootstrapdropdown.setClickedListener(this);

        btn_bootstrapprogressbargroup = ResUtil.findViewById(rootLayout, Id_btn_bootstrapprogressbargroup);
        btn_bootstrapprogressbargroup.setClickedListener(this);

        super.setUIContent(rootLayout);
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }

    @Override
    public void onClick(Component component) {
        Intent intent = new Intent();
        intent.addFlags(Intent.FLAG_ABILITY_NEW_MISSION);
        switch (component.getId()) {
            case ResourceTable.Id_btn_bootstrapbadge:
                present(new BootstrapBadgeExample(), intent);
                break;
            case ResourceTable.Id_btn_bootstrapalert:
                present(new BootstrapAlertExample(), intent);
                break;
            case Id_btn_bootstrapwell:
                present(new BootstrapWellExample(), intent);
                break;
            case Id_btn_bootstraplabel:
                present(new BootstrapLabelExample(), intent);
                break;
            case Id_btn_bootstrapedittext:
                present(new BootstrapEditTextExample(), intent);
                break;
            case Id_btn_bootstrapprogressbar:
                present(new BootstrapProgressBarExample(), intent);
                break;
            case Id_btn_bootstrapthumbnail:
                present(new BootstrapThumbnailExample(), intent);
                break;
            case Id_btn_bootstrapbutton:
                present(new BootstrapButtonExample(), intent);
                break;
            case Id_btn_bootstrapcirclethumbnail:
                present(new BootstrapCircleThumbnailExample(), intent);
                break;
            case Id_btn_bootstrapbuttongroup:
                present(new BootstrapButtonGroupExample(), intent);
                break;
            case Id_btn_bootstrapdropdown:
                present(new BootstrapDropDownExample(), intent);
                break;
            case Id_btn_bootstrapprogressbargroup:
                present(new BootstrapProgressBarGroupExample(), intent);
                break;
            default:
                break;
        }
    }
}
